<?php

include 'config.php';

$mode = $_GET["mode"];


if ($mode == 'all') {
	$query = sprintf("SELECT id, fileName, uploadTime, rateAudio, rateVideo, rateTotal, viewCount FROM uc_images ORDER BY uploadTime ASC");
} elseif ($mode == 'new') {
	$query = sprintf("SELECT id, fileName, uploadTime, rateAudio, rateVideo, rateTotal, viewCount FROM uc_images WHERE viewCount < 1 ORDER BY uploadTime ASC");
} elseif (is_numeric($mode)) {
	$query = sprintf("SELECT id, fileName, uploadTime, rateAudio, rateVideo, rateTotal, viewCount FROM uc_images WHERE id = %d ORDER BY uploadTime ASC", intval($mode));
}

$con = mysql_connect($dbHost,$username,$password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($dbName, $con);
$sth = mysql_query($query);
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $rows[] = $r;
}
print json_encode($rows);

mysql_close($con);

?>
